package com.pay.web.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Properties;

/**
 * properties工具类
 * Created by chenweiyi on 2018/2/7.
 */
public class PropertiesUtils {

    private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    private static Properties properties;

    static {
        properties = new Properties();
        InputStream stream = PropertiesUtils.class.getClassLoader().getResourceAsStream("properties/application.properties");
        try{
            properties.load(stream);
        }catch(Exception e){
            logger.error("Load Properties Fail : {}",e);
        }
    }

    /**
     * 获取某个key的值
     * @param key
     * @param defaultValue
     * @return
     */
    public static String get(String key,String defaultValue){
       return properties.getProperty(key,defaultValue);
    }

    /**
     * 设置某个key的值
     * @param key
     * @param value
     */
    public static void set(String key, String value){
        if(properties.containsKey(key)){
            properties.setProperty(key,value);
        }
    }

    public static void main(String [] args){
        String url = "http://127.0.0.1:8080/intetex-mobile/rest/login/login";
        url = url.substring(0,url.lastIndexOf("/") + 1);
        System.out.println(url);
        System.out.println(String.valueOf(null));
    }

}
